const removeFileProtocol = arg => {
  const fileProto = 'file://'
  if (arg.startsWith(fileProto)) {
    return decodeURIComponent(arg.slice(fileProto.length))
  } else {
    return arg
  }
}

const downloaders = {
  fetch: arg => {
    return fetch(arg)
      .then(response => response.blob())
      .then(blob => URL.createObjectURL(blob))
  },

  getDownloaderFor: arg => {
    if (arg.startsWith('http://') || arg.startsWith('https://')) {
      return downloaders.fetch
    } else {
      return null
    }
  }
}

module.exports = downloaders
